package com.example.activity_day1;

import java.util.ArrayList;

import android.R.anim;
import android.annotation.SuppressLint;
import android.app.ListFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;

@SuppressLint("NewApi")
public class MyListFragment1 extends ListFragment {

	ArrayList<String> fragment = new ArrayList<String>();

	ListAdapter myListAdapter;
	ArrayAdapter<String> adapter;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		// myListAdapter = new ArrayAdapter<String>(getActivity(),
		// android.R.layout.simple_list_item_1, fragment);

		// fragment.add(1+"");
		adapter = new ArrayAdapter<String>(getActivity(),
				android.R.layout.simple_list_item_1, fragment);

		setListAdapter(adapter);

	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		View view = inflater.inflate(R.layout.listfragment1, null);

		Bundle bundle = getArguments();
		if (bundle != null) {

			int detail = bundle.getInt("KEY_DETAIL", 0);

			for (int i = 1; i <= detail; i++) {
				fragment.add(i + "");
			}

			adapter = new ArrayAdapter<String>(getActivity(),
					android.R.layout.simple_list_item_1, fragment);

			setListAdapter(adapter);

		}

		return view;
	}

	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		// Toast.makeText(getActivity(),
		// getListView().getItemAtPosition(position).toString(),
		// Toast.LENGTH_LONG).show();
	}

}
